
function showBusstopListing(id, buslineId, sourceElement){
	//targetDiv = document.getElementById("buslinesSelect");
	var targetDiv = $("#buslinesSelect"); //target div to print results 
            $.ajax({  
                type: "GET", url: '/busstop/select',  
                complete: function(data){  
						targetDiv.show("slow");
						//targetDiv.addClass("busstop-listing-display");
						data.responseText = data.responseText.replace(new RegExp('{JafterID}', 'g'), id);
						data.responseText = data.responseText.replace(new RegExp('{JbuslineID}', 'g'), buslineId);
						$("#buslinesSelect-content").html(data.responseText);  
               }  
            });  
}
function hideBusstopListing(){
	targetDiv = $("#buslinesSelect");
	targetDiv.hide("slow");
}
function startAutomaticHide(){
	$("#buslinesSelect-counter").show("fast");
	automaticHide();
}
var count = 3;
function automaticHide(){
	if(count > 0){
		$("#buslinesSelect-counter").html = count; 
		setTimeout(function(){
			count = count-1;
			$("#buslinesSelect-counter").html(count); 
			automaticHide(count);
		}, 1000);
	}else{
		location.reload();
	}
}

function clickBusstopSelect(afterId, buslineId, busstopId){
	//alert("afterid: "+afterId+" ja busstopId:"+busstopId);
	if(buslineId == "new"){
		newBuslineSendData(extraData = "&addNewBusstop=1&afterId="+afterId+"&newBusstopId="+busstopId);
	}else{
		 $.ajax({  
			type: "POST", url: '/admin/editBuslines',  
			data: "addNewBusstop=1&afterId="+afterId+"&buslineId="+buslineId+"&newBusstopId="+busstopId,
			complete: function(data){  
					$("#buslinesSelect-content").html(data.responseText); 
					//$("#buslinesSelect-content").append(afterId+" ja "+busstopId);
						startAutomaticHide();
			}  
		});  
	}
}



function addNewBuslineShow(){
	var targetDiv = $("#buslinesNewContainer"); //target div to print results 
            $.ajax({  
                type: "GET", url: '/admin/newBusline',  
                complete: function(data){  
						$("#buslinesNewButton").hide();
						targetDiv.show("slow");
						$("#buslinesNewContainer").html(data.responseText);
						location=location+"#buslinesNewContainer"
               }  
            });  
}
function newBuslineSendData(extraData){
	var extraData = (!extraData)?"":extraData;
	var name = $("#buslinesNewContainer #name").val();
	var description = $("#buslinesNewContainer #description").val();
	$('#buslinesNewContainer input[type=checkbox]:checked').each(function() {
		var name = $(this).attr('name');
		var value = $(this).val();
		extraData += "&busstopsForm[]="+value;
	});

	var dataString = 'updateForm=1&name='+ name + '&description=' + description;  
	dataString += extraData;
	$.ajax({  
      type: "POST",  
      url: "/admin/newBusline",  
      data: dataString,  
      complete: function(data) {  
        $("#buslinesNewContainer").html(data.responseText);
      }
    });  
}


function colorMeOnce(form){
	$(form).find("option").each(
		function(){
			$(this).css('background-color', $(this).parent().parent().parent().find("#colorStyle-"+$(this).val()).css('background-color'));
		}
	);
}
	
function colorMeChange(select){
	var selectedId = $(select).find(":selected").val();
	$(select).css('background-color', $(select).parent().parent().find("#colorStyle-"+selectedId).css('background-color'));
}

/*
    var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;  
    //alert (dataString);return false;  
    $.ajax({  
      type: "POST",  
      url: "bin/process.php",  
      data: dataString,  
      success: function() {  
        $('#contact_form').html("<div id='message'></div>");  
        $('#message').html("<h2>Contact Form Submitted!</h2>")  
        .append("<p>We will be in touch soon.</p>")  
        .hide()  
        .fadeIn(1500, function() {  
          $('#message').append("<img id='checkmark' src='images/check.png' />");  
        });  
      }  
    });  
    return false;  

	*/